package com.daodaofun.controller;

import com.daodaofun.entity.Product;
import com.daodaofun.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("product")
public class ProductController {


    @Autowired
    private ProductService productService;

    @RequestMapping("list")
    public String list(Model model){

        List<Product> l = productService.listAll();
        model.addAttribute("products",l);
        return "product/list";
    }

    @RequestMapping("adddata")
    public String addData(Model model){
        productService.addData();
        List<Product> l = productService.listAll();
        model.addAttribute("products",l);
        return "product/list";
    }
}
